package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyCommunityOpenDoorVo;
import com.ruoyi.system.bo.ZsyyCommunityOpenDoorQueryBo;
import com.ruoyi.system.bo.ZsyyCommunityOpenDoorAddBo;
import com.ruoyi.system.bo.ZsyyCommunityOpenDoorEditBo;
import com.ruoyi.system.service.IZsyyCommunityOpenDoorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 开门记录Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "开门记录控制器", tags = {"开门记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/communityOpenDoor")
public class ZsyyCommunityOpenDoorController extends BaseController {

    private final IZsyyCommunityOpenDoorService iZsyyCommunityOpenDoorService;

    /**
     * 查询开门记录列表
     */
    @ApiOperation("查询开门记录列表")
    @PreAuthorize("@ss.hasPermi('system:communityOpenDoor:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyCommunityOpenDoorVo> list(@Validated ZsyyCommunityOpenDoorQueryBo bo) {
        return iZsyyCommunityOpenDoorService.queryPageList(bo);
    }

    /**
     * 导出开门记录列表
     */
    @ApiOperation("导出开门记录列表")
    @PreAuthorize("@ss.hasPermi('system:communityOpenDoor:export')")
    @Log(title = "开门记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyCommunityOpenDoorVo> export(@Validated ZsyyCommunityOpenDoorQueryBo bo) {
        List<ZsyyCommunityOpenDoorVo> list = iZsyyCommunityOpenDoorService.queryList(bo);
        ExcelUtil<ZsyyCommunityOpenDoorVo> util = new ExcelUtil<ZsyyCommunityOpenDoorVo>(ZsyyCommunityOpenDoorVo.class);
        return util.exportExcel(list, "开门记录");
    }

    /**
     * 获取开门记录详细信息
     */
    @ApiOperation("获取开门记录详细信息")
    @PreAuthorize("@ss.hasPermi('system:communityOpenDoor:query')")
    @GetMapping("/{id7}")
    public AjaxResult<ZsyyCommunityOpenDoorVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id7") Long id7) {
        return AjaxResult.success(iZsyyCommunityOpenDoorService.queryById(id7));
    }

    /**
     * 新增开门记录
     */
    @ApiOperation("新增开门记录")
    @PreAuthorize("@ss.hasPermi('system:communityOpenDoor:add')")
    @Log(title = "开门记录", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyCommunityOpenDoorAddBo bo) {
        return toAjax(iZsyyCommunityOpenDoorService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改开门记录
     */
    @ApiOperation("修改开门记录")
    @PreAuthorize("@ss.hasPermi('system:communityOpenDoor:edit')")
    @Log(title = "开门记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyCommunityOpenDoorEditBo bo) {
        return toAjax(iZsyyCommunityOpenDoorService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除开门记录
     */
    @ApiOperation("删除开门记录")
    @PreAuthorize("@ss.hasPermi('system:communityOpenDoor:remove')")
    @Log(title = "开门记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{id7s}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] id7s) {
        return toAjax(iZsyyCommunityOpenDoorService.deleteWithValidByIds(Arrays.asList(id7s), true) ? 1 : 0);
    }
}
